import React,{Component} from "react";
import {connect} from 'react-redux'
import {Button, InputItem, NavBar, TextareaItem} from "antd-mobile";
import {Redirect} from "react-router-dom";

import {Update} from "../../redux/actions";
import HeadSelector from "../../components/head-select/head-selector";
//下面的axios是用来调试的
import {reqUpdate} from '../../api/index'
import axios from 'axios'

class Dasheninfo extends Component{
    state = { header: '', // 头像名称
        info: '', // 个人简介
        post: '', // 求职岗位
         }

    change = (item,val) =>{

        this.setState({[item]:val})
    }
    baocun =()=>{
        console.log(this.state)
        this.props.Update(this.state)
        //调试代码
       /* reqUpdate().then(res=>{
            console.log(res.data)
        })*/
       /* axios.post('/update')
            .then(response=>{
                console.log(response.data)
            })*/

    }
    setHeader= (header)=>{
        this.setState({header:header})
    }
    render() {
        const {header} = this.props
        if(header){
            //用户的信息已经完善，跳转到大神主界面
            return <Redirect to='/dashen'></Redirect>
        }
        return(
            <div>
                <NavBar>大神信息完善</NavBar>
                <HeadSelector setHeader ={this.setHeader}></HeadSelector>
                <InputItem placeholder='请输入求职岗位' onChange={(val)=>this.change("post",val)}>求职岗位：</InputItem>
                <InputItem placeholder='请输入个人介绍' onChange={(val)=>this.change("info",val)}>个人介绍：</InputItem>
                <Button style={{backgroundColor:"green"}} onClick={this.baocun}>保存</Button>
            </div>
        )
    }
}
export default connect(
    state=>(state.user),
    {Update}
)(Dasheninfo)